Instead of manually typing inconsole.log
five times, we can use afor
loop to do this. The aim of this exercise is just to show you how a for
loop looks, and demonstrate how useful it is. Subsequent exercises will
a. walk you through the syntax bit by bit
b. explain how the computer thinks as it executes a for
loop.
We initially focus on using for
loops just to count numbers to keep things simple. But by section 3, we will show you how to do more fancy things!